/**
 * @author FengLei.You
 */
function LayerManager(opt){
	this._layers={};
	this._indexSize=0;
	
	this._top=opt.top||0;
	this._left=opt.left||0;
	this._width=opt.width||0;
	this._height=opt.height||0;
}
LayerManager.prototype.append=function(layer){
	this._layers[++this._indexSize]=layer;
}
LayerManager.prototype.getLayerAt=function(index){
	return this._layers[index];
}
LayerManager.prototype.getLength=function(){
	return this._indexSize;
}
LayerManager.prototype.insert=function(index,layer){
	if(index>this._indexSize){
		this._layers[index]=layer;
		this._indexSize=index;
		return;
	}
	
	for(var idx=index;idx<this._indexSize;idx++){
		this._layers[idx+1]=this._layers[idx];
	}
	this._layers[idx]=layer;
	this._indexSize++;
}
LayerManager.prototype.remove=function(index){
	this._layers[index]=null;
}
LayerManager.prototype.setViewWindow=function(top,left,width,height){
	this._top=top;
	this._left=left;
	this._width=width;
	this._height=height;
}
LayerManager.prototype.paint=function(top,left,context){
	this._top=top;
	this._left=left;
	
	for(var i=0;i<this._indexSize;i++){
		var layer=this._layers[i];
		if(layer){
			layer.paint(context);
		}
	}
}
